package com.gs.SynAntiWandering.adapter;

import android.content.Context;
import android.view.View;

import com.gs.SynAntiWandering.R;
import com.gs.SynAntiWandering.adapter.base.BaseAdapter;
import com.gs.SynAntiWandering.adapter.base.BaseViewHolder;
import com.gs.SynAntiWandering.constant.AllConstants;
import com.gs.SynAntiWandering.db.dto.MemberDto;
import com.gs.SynAntiWandering.db.dto.RecordDto;
import com.gs.SynAntiWandering.util.DateUtil;
import com.gs.SynAntiWandering.util.SPUtil;

import java.util.List;


public class RecordAdapter extends BaseAdapter<RecordDto> {


    public RecordAdapter(Context context, List<RecordDto> mDatas, int layoutId) {
        super(context, mDatas, layoutId);
    }

    @Override
    public void convert(BaseViewHolder holder, RecordDto item, final int position) {
        holder.setText(R.id.tv_first, item.getCardNo() == null ? "" : item.getCardNo());
        if (item.getTime() != null) {
            holder.setText(R.id.tv_second, DateUtil.getInstance().DateTimeToStr(item.getTime()));
            holder.setText(R.id.tv_third, DateUtil.getInstance().DateTimeToStr(item.getTime(), "HH:mm:ss"));
        }
        StringBuilder sb = new StringBuilder();
        if (item.getMember() != null) {
            MemberDto member = item.getMember();
            if (SPUtil.getInstance().getInt(AllConstants.LANGUAGE, 1) == 1) {
                sb.append(member.getCnName() == null ? "" : member.getCnName());
            } else {
                sb.append(member.getEnName() == null ? "" : member.getEnName());
            }
            if (member.getMemberType() != null) {
                sb.append(" - ").append(member.getMemberType().getName());
            }
            if (member.getFloor() != null) {
                sb.append("\n").append(member.getFloor().getName());
            }
        }
        if (item.getDevice() != null) {
            sb.append("\n").append(item.getDevice().getName());
        }
        holder.setText(R.id.tv_fourth,sb.toString());
        if (item.getIoType() != null) {
            if (item.getIoType() == 1) {
                holder.setVisibility(R.id.item_type_o, View.GONE);
                holder.setVisibility(R.id.item_type_i, View.VISIBLE);
            } else if (item.getIoType() == 2) {
                holder.setVisibility(R.id.item_type_o, View.VISIBLE);
                holder.setVisibility(R.id.item_type_i, View.GONE);
            } else if (item.getIoType() == 3) {
                holder.setVisibility(R.id.item_type_o, View.VISIBLE);
                holder.setVisibility(R.id.item_type_i, View.VISIBLE);
            }
        }
    }
}
